;;-*- Emacs-Lisp -*-
;;
;;Time-stamp: <Sat Oct 27 10:04:18 CST 2012 by wfg>
;;
;;basic settings for emacs
;;
;;
;;remove scroll-bar,tool-bar and menu-bar
(scroll-bar-mode -1)
(tool-bar-mode -1)
;(menu-bar-mode nil) 

;; 打开图片显示功能
(auto-image-file-mode t)

;;显示括号匹配
(show-paren-mode t)

;;把缺省的 major mode 设置为 text-mode, 而不是几乎什么功能也没有的 fundamental-mode
(setq default-major-mode 'text-mode)

;;打开文件的缺省路径
(setq default-directory "~/")

;; 设定不产生备份文件
(setq make-backup-files nil)

;;自动保存模式
(setq auto-save-mode nil)

;; 不生成临时文件
(setq-default make-backup-files nil)

;;允许emacs和外部其他程序的粘贴
(setq x-select-enable-clipboard t)

;;在行首C-k时，同时删除该行
(setq-default kill-whole-line t)

;;以y/n代表yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;;显示行号和列号
(global-linum-mode t)
(column-number-mode t)

;;在标题栏显示buffer的名字
;(setq frame-title-format "emacs@%b")

;;set tab width to 8 for all buffers
;(setq-default tab-width 4  c-basic-offset 4)

;;支持 ANSI color 
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) 
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on t) 

;;; 设置标题栏显示文件完整的路径名
(setq frame-title-format 
'("%S" (buffer-file-name "%f"
(dired-directory dired-directory "%b"))))

;;Use YaHei for han, cjk-misc and gb18030 charset
(setq cn-char-size 18)
(set-fontset-font "fontset-default"
	     'han (font-spec :family "Microsoft YaHei" :size cn-char-size))
(set-fontset-font "fontset-default"
        'cjk-misc (font-spec :family "Microsoft YaHei" :size cn-char-size))
(set-fontset-font "fontset-default"
	 'gb18030 (font-spec :family "Microsoft YaHei" :size cn-char-size))
(set-fontset-font "fontset-default"
          'symbol (font-spec :family "Microsoft YaHei" :size cn-char-size))

;;显示时间设置
(display-time-mode 1);;启用时间显示设置，在minibuffer上面的那个杠上
(setq display-time-24hr-format t);;时间使用24小时制
(setq display-time-day-and-date t);;时间显示包括日期和具体时间
(setq display-time-use-mail-icon t);;时间栏旁边启用邮件设置
(setq display-time-interval 10);;时间的变化频率

;;disable theme background color in terminal
(defun on-after-init()
  (unless (display-graphic-p (selected-frame))
    (set-face-background 'default "unspecified-bg" (selected-frame))))
(add-hook 'window-setup-hook 'on-after-init)

;;shell结束后自动终止buffer
(add-hook 'shell-mode-hook 'wfg-shell-mode-hook-func)
(defun wfg-shell-mode-hook-func  ()
  (set-process-sentinel (get-buffer-process (current-buffer))
                            #'wfg-shell-mode-kill-buffer-on-exit))
(defun wfg-shell-mode-kill-buffer-on-exit (process state)
  (message "%s" state)
  (if (or
       (string-match "exited abnormally with code.*" state)
       (string-match "finished" state))
      (kill-buffer (current-buffer))))

(provide 'basic-settings)
;;basics ends here
